package com.osgc.rf.unit.dao;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Category;

import com.inca.np.gui.control.DBTableModel;
import com.inca.np.util.SelectHelper;

public class GoodsStatusInfo {
	
	static  protected Category logger = Category.getInstance(GoodsStatusInfo.class);
	private String goodsstatusid;
	private	String goodsstatus;
	private String quantitystatus;
	private String useflag;

	public GoodsStatusInfo() {
	}

	public GoodsStatusInfo(String goodsstatusid, String goodsstatus,
			String quantitystatus, String useflag) {
		setGoodsstatus(goodsstatus);
		setGoodsstatusid(goodsstatusid);
		setQuantitystatus(quantitystatus);
		setUseflag(useflag);
	}

	static public List<GoodsStatusInfo> getGoodsStatusInfos(Connection con)
			throws Exception {
		List<GoodsStatusInfo> statusinfos = new ArrayList<GoodsStatusInfo>();
		GoodsStatusInfo statusinfo = null;
		String sql = "select t.goodsstatusid,t.goodsstatus,a.ddlname quantitystatus," +
				" b.ddlname useflag from wms_goodsstatus t,sys_ddl_all_v a,sys_ddl_all_v b " +
				" where a.keyword='TPL_QUANTITYSTATUS' and t.quantitystatus=a.ddlid(+) " +
				" and b.keyword='WMS_USEFLAG' and t.useflag=b.ddlid(+)";
		logger.debug(sql);
		DBTableModel db = new SelectHelper(sql).executeSelect(con, 0, 1000);
		if(db.getRowCount()==0)return null;
		for (int i = 0; i < db.getRowCount(); i++) {
			String goodsstatusid = db.getItemValue(i, "goodsstatusid");
			String goodsstatus = db.getItemValue(i, "goodsstatus");
			String quantitystatus = db.getItemValue(i, "quantitystatus");
			String useflag ="";
			statusinfo = new GoodsStatusInfo(goodsstatusid, goodsstatus,
					quantitystatus, useflag);
			statusinfos.add(statusinfo);
		}
		return statusinfos;

	}

	public String getGoodsstatusid() {
		return goodsstatusid;
	}

	public void setGoodsstatusid(String goodsstatusid) {
		this.goodsstatusid = goodsstatusid;
	}

	public String getGoodsstatus() {
		return goodsstatus;
	}

	public void setGoodsstatus(String goodsstatus) {
		this.goodsstatus = goodsstatus;
	}

	public String getQuantitystatus() {
		return quantitystatus;
	}

	public void setQuantitystatus(String quantitystatus) {
		this.quantitystatus = quantitystatus;
	}

	public String getUseflag() {
		return useflag;
	}

	public void setUseflag(String useflag) {
		this.useflag = useflag;
	}

	public static String getQuantitystatus(Connection con, String goodsstatusid) throws Exception {
		String sql = "select quantitystatus from wms_goodsstatus where goodsstatusid = "+goodsstatusid;
		DBTableModel db = new SelectHelper(sql).executeSelect(con, 0, 1);
		if(db.getRowCount()>0)return db.getItemValue(0, "quantitystatus");
		return null;
	}

}
